package com.fanhao.dllo.justforyou.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.util.Log;

import com.fanhao.dllo.justforyou.entity.NewsViewPageResult;
import com.fanhao.dllo.justforyou.fragment.NewsTopFragment;

import java.util.List;

/**
 * Created by dllo on 15/11/2.
 */
public class NewsViewPageAdapter extends FragmentPagerAdapter {
    private List<NewsViewPageResult.HeadlineAdEntity> headline_ad;



    // 设置点击跳转
    private NewsViewPageOnClickListener listener;
    // 抽象方法
    private interface NewsViewPageOnClickListener {
        void onItemClickListener ();
    }


    public void addData(List<NewsViewPageResult.HeadlineAdEntity> datas){
        this.headline_ad = datas;
        notifyDataSetChanged();
    }

    public NewsViewPageAdapter(FragmentManager fm) {
        super(fm);

    }




    @Override
    public Fragment getItem(int position) {

        NewsViewPageResult.HeadlineAdEntity headline_ads= headline_ad.get(position);

        int itemposition = position;
        String title = headline_ads.getTitle();
        String imgSrc = headline_ads.getImgsrc();
        String url=headline_ads.getUrl();
        return NewsTopFragment.getInstance(title, imgSrc,url,itemposition);
    }

    @Override
    public int getCount() {
        return headline_ad != null && headline_ad.size() > 0 ?
                headline_ad.size() : 0;
    }
}
